<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Match Predictions</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
background-color: #1C1C1C;
color: #f0f0f0;
font-family: Arial, sans-serif;
padding: 1rem;
}
h1 {
margin-bottom: 1rem;
text-align: center;
color: #fff;
}
table {
width: 100%;
border-collapse: collapse;
margin: 0 auto;
}
thead tr { background-color: #2B2B2B; }
th, td {
padding: 0.8rem;
text-align: center;
border-bottom: 1px solid #333;
vertical-align: middle;
}
tr:hover { background-color: #292929; }
.team-logo {
width: 24px;
height: 24px;
vertical-align: middle;
margin-right: 5px;
}
.score-container {
display: flex;
justify-content: center;
gap: 8px;
}
.score-box {
width: 32px;
height: 32px;
background-color: #3a7f0d;
border: 2px solid #00ff00;
border-radius: 4px;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
color: #fff;
margin: 0 4px;
}
.predict-btn {
background-color: #007BFF;
color: #fff;
padding: 0.5rem 1rem;
border: none;
border-radius: 4px;
cursor: pointer;
font-weight: bold;
position: relative;
transition: background-color 0.3s;
}
.predict-btn:hover { background-color: #0056b3; }
.predict-btn:disabled {
background-color: #666;
cursor: not-allowed;
}
.btn-text { display: inline-block; }
.spinner {
display: none;
width: 20px;
height: 20px;
border: 3px solid #fff;
border-top: 3px solid #007BFF;
border-radius: 50%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
animation: spin 0.8s linear infinite;
}
@keyframes spin {
0% { transform: translate(-50%, -50%) rotate(0deg); }
100% { transform: translate(-50%, -50%) rotate(360deg); }
}
.no-matches {
color: #ff6600;
margin-top: 1rem;
text-align: center;
font-weight: bold;
}
</style>
<!DOCTYPE html>
Line 1: Informs the browser that this document is in HTML5 format.
<html lang="en">
Line 2: Begins the HTML document with English set as the main language.
<head>
Line 3: Start of the head section that contains metadata for the document.
<meta charset="UTF-8" />
Line 4: Specifies UTF-8 as the character encoding to support all universal characters.
<title>Match Predictions</title>
Line 5: Defines the title of the page shown in the browser tab.
<style>
Line 6: Starts the CSS section for the page's visual styling.
* { margin: 0; padding: 0; box-sizing: border-box; }
Line 7: Resets all default margins and paddings, and sets box-sizing for better layout control.
body {
background-color: #1C1C1C;
color: #f0f0f0;
font-family: Arial, sans-serif;
padding: 1rem;
}
Lines 8-13: Sets a dark background, light text, readable font, and spacing around the body content.
h1 {
margin-bottom: 1rem;
text-align: center;
color: #fff;
}
Lines 14-18: Styles the main heading: centered, white, and with bottom margin.
table {
width: 100%;
border-collapse: collapse;
margin: 0 auto;
}
Lines 19-23: Configures the table to be full-width, borderless between cells, and centered.
thead tr { background-color: #2B2B2B; }
Line 24: Applies a dark gray background to the table header row.
th, td {
padding: 0.8rem;
text-align: center;
border-bottom: 1px solid #333;
vertical-align: middle;
}
Lines 25-30: Common styling for table cells: centered content, bottom border, and internal spacing.
tr:hover { background-color: #292929; }
Line 31: Highlights the table row when hovered over.
.team-logo {
width: 24px;
height: 24px;
vertical-align: middle;
margin-right: 5px;
}
Lines 32-37: Styles for team logos: small, vertically centered, with spacing on the right.
.score-container {
display: flex;
justify-content: center;
gap: 8px;
}
Lines 38-42: Flexbox layout to center and space out the score boxes.
.score-box {
width: 32px;
height: 32px;
background-color: #3a7f0d;
border: 2px solid #00ff00;
border-radius: 4px;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
color: #fff;
margin: 0 4px;
}
Lines 43-55: Green styled box for displaying predicted scores with centered white text.
.predict-btn {
background-color: #007BFF;
color: #fff;
padding: 0.5rem 1rem;
border: none;
border-radius: 4px;
cursor: pointer;
font-weight: bold;
position: relative;
transition: background-color 0.3s;
}
Lines 56-65: Styles the prediction button: blue, rounded, clickable with hover effect.
.predict-btn:hover { background-color: #0056b3; }
.predict-btn:disabled { background-color: #666; cursor: not-allowed; }
Lines 66-67: Changes appearance when hovered or disabled.
.btn-text { display: inline-block; }
Line 68: Ensures the button text behaves like an inline block for layout control.
.spinner {
display: none;
width: 20px;
height: 20px;
border: 3px solid #fff;
border-top: 3px solid #007BFF;
border-radius: 50%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
animation: spin 0.8s linear infinite;
}
Lines 69-80: Defines a hidden circular loading spinner with a spinning animation.
@keyframes spin {
0% { transform: translate(-50%, -50%) rotate(0deg); }
100% { transform: translate(-50%, -50%) rotate(360deg); }
}
Lines 81-84: CSS animation to rotate the spinner infinitely.
.no-matches {
color: #ff6600;
margin-top: 1rem;
text-align: center;
font-weight: bold;
}
Lines 85-90: Styles the message shown when no matches are available.
</style>
Line 91: Ends the CSS style section.
<script>
<script>
function predictMatch(fixtureId, homeTeamId, awayTeamId, leagueId, season) {
const button = document.getElementById("btn-" + fixtureId);
const spinner = button.querySelector(".spinner");
const btnText = button.querySelector(".btn-text");
button.disabled = true;
btnText.style.display = "none";
spinner.style.display = "block";
const payload = {
fixture_id: fixtureId,
home_team_id: homeTeamId,
away_team_id: awayTeamId,
league_id: leagueId,
season: season
};
fetch("/predict", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload)
})
.then(response => response.json())
.then(data => {
spinner.style.display = "none";
if (data.error) {
alert("Error: " + data.error);
btnText.style.display = "inline-block";
button.disabled = false;
return;
}
const parts = data.predicted_score.split(" - ");
if (parts.length === 2) {
document.getElementById("score-home-" + fixtureId).textContent = parts[0];
document.getElementById("score-away-" + fixtureId).textContent = parts[1];
}
btnText.style.display = "inline-block";
})
.catch(err => {
spinner.style.display = "none";
btnText.style.display = "inline-block";
button.disabled = false;
alert("Request error: " + err);
});
}
</script>
Line 1: Start of the JavaScript block.
function predictMatch(fixtureId, homeTeamId, awayTeamId, leagueId, season) {
Line 2: Defines a function named predictMatch that takes the match details as parameters.
const button = document.getElementById("btn-" + fixtureId);
Line 3: Selects the prediction button by its ID using the fixture ID.
const spinner = button.querySelector(".spinner");
Line 4: Selects the loading spinner element inside the button.
const btnText = button.querySelector(".btn-text");
Line 5: Selects the text span element of the button.
button.disabled = true;
Line 6: Disables the button to prevent multiple clicks.
btnText.style.display = "none";
Line 7: Hides the button text.
spinner.style.display = "block";
Line 8: Displays the loading spinner.
const payload = {
Line 9: Creates a JavaScript object named payload to hold the match info.
fixture_id: fixtureId, home_team_id: homeTeamId, away_team_id: awayTeamId, league_id: leagueId, season: season
Lines 10-14: Assigns the function parameters to the payload object.
};
Line 15: Ends the payload object declaration.
fetch("/predict", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload)
})
Lines 16-20: Sends an HTTP POST request to the /predict endpoint with the JSON payload.
.then(response => response.json())
Line 21: Converts the response into JSON format.
.then(data => {
Line 22: Begins the processing of the returned prediction data.
spinner.style.display = "none";
Line 23: Hides the spinner after receiving the response.
if (data.error) {
Line 24: Checks if the API response contains an error.
alert("Error: " + data.error);
Line 25: Displays the error message in an alert box.
btnText.style.display = "inline-block";
Line 26: Re-displays the button text.
button.disabled = false;
Line 27: Re-enables the button.
return;
Line 28: Stops further processing if there's an error.
}
Line 29: End of error block.
const parts = data.predicted_score.split(" - ");
Line 30: Splits the predicted score string into home and away parts.
if (parts.length === 2) {
Line 31: Verifies the format contains both parts (home and away scores).
document.getElementById("score-home-" + fixtureId).textContent = parts[0];
document.getElementById("score-away-" + fixtureId).textContent = parts[1];
Lines 32-33: Updates the HTML content with predicted scores.
}
Line 34: End of condition checking for correct score format.
btnText.style.display = "inline-block";
Line 35: Restores the display of the button text.
})
Line 36: End of the second then() block.
.catch(err => {
Line 37: Begins error handling for fetch failure.
spinner.style.display = "none";
btnText.style.display = "inline-block";
button.disabled = false;
alert("Request error: " + err);
Lines 38-41: Reverts the UI to its normal state and shows an alert with the error message.
});
Line 42: End of the catch() block.
</script>
Line 43: End of the JavaScript block.
<body>
</head>
<body>
<h1>Match Predictions</h1>
<table>
<thead>
<tr>
<th>Date</th>
<th>Competition</th>
<th>Match</th>
<th>Scores</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{% if matches and matches|length > 0 %}
{% for match in matches %}
<tr>
<td>{{ match.date }}</td>
<td>{{ match.league }}</td>
<td>
<img src="{{ match.home_logo }}" alt="Logo of {{ match.home_team }}" class="team-logo" />
{{ match.home_team }} vs
<img src="{{ match.away_logo }}" alt="Logo of {{ match.away_team }}" class="team-logo" />
{{ match.away_team }}
</td>
<td>
<div class="score-container">
<div class="score-box" id="score-home-{{ match.fixture_id }}">--</div>
<div class="score-box" id="score-away-{{ match.fixture_id }}">--</div>
</div>
</td>
<td>
<button class="predict-btn" id="btn-{{ match.fixture_id }}"
onclick="predictMatch('{{ match.fixture_id }}','{{ match.home_team_id }}','{{ match.away_team_id }}','{{ match.league_id }}','{{ match.season }}')">
<span class="btn-text">Predict Score</span>
<div class="spinner"></div>
</button>
</td>
</tr>
{% endfor %}
{% else %}
<tr>
<td colspan="5">
<div class="no-matches">
No club matches found for this period (international break or end of season?)
</div>
</td>
</tr>
{% endif %}
</tbody>
</table>
</body>
</html>
Line 1: Starts the HTML body section where visible content will be rendered.
<h1>Match Predictions</h1>
Line 2: Displays a main heading at the top of the page titled "Match Predictions".
<table>
Line 3: Begins an HTML table that will list upcoming football matches and predictions.
<thead> <tr> <th>Date</th> <th>Competition</th> <th>Match</th> <th>Scores</th> <th>Action</th> </tr> </thead>
Lines 4-11: Table header with five columns: Date, Competition, Match, Scores, and Action.
<tbody>
{% if matches and matches|length > 0 %}
{% for match in matches %}
Lines 12-14: Jinja2 condition and loop to display matches only if the list is not empty.
<tr>
<td>{{ match.date }}</td>
<td>{{ match.league }}</td>
<td>
<img src="{{ match.home_logo }}" alt="Logo of {{ match.home_team }}" class="team-logo" />
{{ match.home_team }} vs
<img src="{{ match.away_logo }}" alt="Logo of {{ match.away_team }}" class="team-logo" />
{{ match.away_team }}
</td>
Lines 15-22: Table row showing match date, league name, and both team names with logos.
<td>
<div class="score-container">
<div class="score-box" id="score-home-{{ match.fixture_id }}">--</div>
<div class="score-box" id="score-away-{{ match.fixture_id }}">--</div>
</div>
</td>
Lines 23-28: Placeholder score boxes to later display predicted home and away scores.
<td>
<button class="predict-btn" id="btn-{{ match.fixture_id }}"
onclick="predictMatch('{{ match.fixture_id }}','{{ match.home_team_id }}','{{ match.away_team_id }}','{{ match.league_id }}','{{ match.season }}')">
<span class="btn-text">Predict Score</span>
<div class="spinner"></div>
</button>
</td>
</tr>
Lines 29-36: Predict button for each match with spinner. On click, it triggers the `predictMatch()` function.
{% endfor %}
{% else %}
Lines 37-38: End of the loop. If there are no matches, the `else` block is triggered.
<tr> <td colspan="5"> <div class="no-matches"> No club matches found for this period (international break or end of season?) </div> </td> </tr>
Lines 39-45: Displays a message across the table if no matches are available to show.
{% endif %}
</tbody>
</table>
</body>
Lines 46-50: Closes the table and body tags, ending the main content section.
</html>
Line 51: Closes the HTML document.